<!doctype html>
<html lang="zh-hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>显示当前时间</title>
</head>
<body>
  <h1></h1>
  <script>
      var h1=document.querySelector("h1");
      function updateNow(){
          var xhr=new XMLHttpRequest();
          xhr.open("GET","/chatroom/now");
          xhr.onload=function(){
              var now=xhr.responseText;
              h1.innerText=now;
          }
          xhr.send();
      }
      updateNow();
      setInterval(updateNow,1000);
  </script>
</body>
</html>